#include<iostream>
using namespace std;
#define int long long
const int N = 1e5 + 10;
int a[N];
int n , q;
int find(int x , int y)
{
    int left = 1 , right = n;
    while(left < right)
    {
        int mid = (left + right) / 2;
        if(a[mid] >= x) right = mid;
        else left = mid + 1;
    }
    if(a[left] < x) return 0;
    int l = left;
    left = 1 , right = n;
    while(left < right)
    {
        int mid = (left + right + 1) / 2;
        if(a[mid] <= y) left = mid;
        else right = mid - 1;
    }
    if(a[right] > y) return 0;
    return right - l + 1;
}
signed main()
{
    cin >> n;
    for(int i = 1;i <= n;i ++) cin >> a[i];
    cin >> q;
    while(q--)
    {
        int x , y;
        cin >> x >> y;
        cout << find(x , y) << endl;
    }
    return 0;
}